package com.atguigu.collection;

import org.assertj.core.util.Lists;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class CollectionDemo {
    public static void main(String[] args) {
        Product prod1 =  new Product(1,1,15,"面包","零食");
        Product prod2 = new Product(2, 2, 20, "饼干", "零食");
        Product prod3 = new Product(3, 3, 30, "月饼", "零食");
        Product prod4 = new Product(4, 3, 10, "青岛啤酒", "啤酒");
        Product prod5 = new Product(5, 10, 15, "百威啤酒", "啤酒");

        //把对象转换为集合
        ArrayList<Product> productList = Lists.newArrayList(prod1, prod2, prod3, prod4, prod5);
        //对集合继续迭代
//        productList.forEach(product -> {
//            System.out.println(product);
//        });
        productList.stream().forEach(product -> {
            System.out.println(product);
        });

        //对商品进行分组分类
        Map<String, List<Product>> productMap = productList.stream().collect(Collectors.groupingBy(Product::getCategory));
        Set<Map.Entry<String, List<Product>>> productSet = productMap.entrySet();
        for (Map.Entry<String, List<Product>> productEntry : productMap.entrySet()) {
            System.out.print(productEntry.getKey());
            System.out.println(productEntry.getValue());
        }
//        productSet.forEach(productEntry->{
//            System.out.print(productEntry.getKey());
//            System.out.println(productEntry.getValue());
//        });

        ArrayList<String> characterList = new ArrayList<>();
        characterList.add("a");
        characterList.add("b");
        characterList.add("c");

        List<String> upperList = characterList.stream().map(character -> {
            return character.toUpperCase();
        }).collect(Collectors.toList());

        System.out.println(upperList);

    }
}
